package com.feidee.bigdata.controller;

import com.feidee.bigdata.model.CommonResponse;
import com.feidee.bigdata.model.Payment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @Author:CHQ
 * @Date:2020/4/7 18:07
 * @Description
 */
@RestController
public class ConsumerController {
    private static final Logger logger = LoggerFactory.getLogger(ConsumerController.class);
    private static final String REQUEST_URL = "http://PAYMENT-SERVICE";
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/consume")
    @ResponseBody
    public CommonResponse<Payment> consume(@RequestBody Payment payment) {
        return restTemplate.postForObject(REQUEST_URL + "/insert", payment, CommonResponse.class);
    }

    @RequestMapping("/query/{id}")
    @ResponseBody
    public CommonResponse<Payment> query(@PathVariable Long id) {
        return restTemplate.getForObject(REQUEST_URL + "/select/" + id, CommonResponse.class);
    }

    @RequestMapping("/queryZipkin")
    public String queryZipkin() {
        return restTemplate.getForObject(REQUEST_URL + "/zipkin", String.class);
    }
}
